package com.qfly.main.repository;

import com.qfly.main.model.entity.SysResource;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ResourceRepository extends JpaRepository<SysResource, Long> {

    @Query(value = "select p.*" +
            "        from sys_user u" +
            "        LEFT JOIN sys_user_role sru on u.id= sru.user_id" +
            "        LEFT JOIN sys_role r on sru.role_id=r.id" +
            "        LEFT JOIN sys_role_resource spr on spr.role_id=r.id" +
            "        LEFT JOIN sys_resource p on p.id =spr.resource_id" +
            "        where u.id=:userId", nativeQuery = true)
    List<SysResource> findByAdminUserId(@Param("userId") Long userId);
}
